package cn.sccdlg.spring5.ui;

import cn.sccdlg.spring5.service.AccountService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author RaoShuang
 * @emil 991207823@qq.com
 * @date 2020/10/18 21:17
 * 模拟一个表现层，用于调用业务层
 */
public class Client {

    /**
     * @param args
     */
    public static void main(String[] args) {
        //1.获取核心容器对象
//        ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");
        ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");
        //2.根据id获取Bean对象
        //2-1、@Component没有配置其他属性
//        AccountService as  = (AccountService)ac.getBean("accountServiceImpl");
        //2-2、@Component指定value值，写法@Component(value="accountService")（可略）
        AccountService as  = (AccountService)ac.getBean("accountService");
        System.out.println(as);
//        as.saveAccount();
        //2-3、@Autowired自动按照类型注入的缺陷（保证唯一一份）
//        IAccountDao adao = ac.getBean("accountDao", IAccountDao.class);
//        System.out.println(adao);
        //2-4、@Scope 配置单例还是多例（默认时单例，单例时可省略注解）
        AccountService as2  = (AccountService)ac.getBean("accountService");
        System.out.println(as2);
        System.out.println(as == as2);
        ac.close();
    }

}
